using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class sqlConnectionData
    {
        public static SqlConnection Connection()
        {
        SqlConnection cnn = new SqlConnection("Server.;Database");
        return cnn;
        }
    }
    public class Users_DAO
    {
        public static DataTable Loadd(){
            SqlConnection cnn = sqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("Sp_login",cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dtb = new DataTable();
            da.Fill(dtb);
            return dtb;
        }

        public static void AddNew(Users_DTO users)
        {
            SqlConnection cnn = sqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("Sp_themmoi", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@username",SqlDbType.NVarChar,50).Value=users.UserName;
            cmd.Parameters.Add("@password",SqlDbType.NVarChar,50).Value=users.PassWord;
            cmd.Parameters.Add("@permistionId", SqlDbType.Int, 50).Value=users.PermistionId;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }

        public static void dalete(int id)
        {
            SqlConnection cnn = sqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_delete",cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@id",SqlDbType.Int).Value=id;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }

        public static DataTable Search(int permistionid)
        {
            SqlConnection cnn = sqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_search",cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@permistionid",SqlDbType.Int).Value=permistionid;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dtb = new DataTable();
            da.Fill(dtb);
            return dtb;
        }
    }

    public class Permistion_DAO
    {
        public static DataTable List()
        {
            SqlConnection cnn = sqlConnectionData.Connection();
            SqlCommand cmd=new SqlCommand("sp_list",cnn);
            cmd.CommandType=CommandType.StoredProcedure;
            SqlDataAdapter da=new SqlDataAdapter(cmd);
            DataTable dtb=new DataTable();
            da.Fill(dtb);
            return dtb;
        }
    }
}
